<template>
    <div @paste="handlePaste">
      <el-table :data="tableData" stripe>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="age" label="年龄"></el-table-column>
      </el-table>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue';
  
  const tableData = ref([
    { name: '张三', age: 20 },
    { name: '李四', age: 25 }
  ]);
  
  const handlePaste = (event) => {
    const clipboardData = event.clipboardData || window.clipboardData;
    const pastedData = clipboardData.getData('text');
  
    // 解析粘贴的数据
    const rows = pastedData.split('\n');
    const newData = [];
    rows.forEach((row) => {
      const cells = row.split('\t');
      if (cells.length > 1) {
        newData.push({
          name: cells[0],
          age: parseInt(cells[1])
        });
      }
    });
  
    // 更新表格数据
    tableData.value = newData;
  };
  </script>